/*
* ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
* Without permission, no one has the right to obtain, disclose or use this software in any way.
*/

package ecarx.xsf.notificationcenter.scenecard;


import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import java.util.List;

/**
 * FileName: ISceneCardInfo.java <br>
 * Description : 智能卡片数据 <br>
 * Create Time: 2021/8/3 14:07 <br>
 * Update Time: 2021/8/3 14:07 <br>
 *
 * @since 1.0.0
 */
public class ISceneCardInfo implements Parcelable, Comparable<ecarx.xsf.notificationcenter.scenecard.ISceneCardInfo> {

    /**
     * 场景卡片id
     */
    private int id;

    /**
     * 发起方包名
     */
    private String pkgname;

    /**
     * 是否播放提示音
     */
    private boolean beep;

    /**
     * 是否 tts 播报
     */
    private boolean tts;

    /**
     * 是否支持可见即可说
     */
    private boolean seeSay;

    /**
     * 场景卡片主标题
     */
    private String title;

    /**
     * 场景卡片副标题
     */
    private String subtitle;

    /**
     * 场景背景图片
     */
    private String background;

    /**
     * 场景卡片内容消息背景图
     */
    private String detailImg;

    /**
     * 消息标识符
     */
    private String tag;

    /**
     * 场景消息发送时间
     */
    private long when;

    /**
     * 按钮点击事件
     */
    private List<IPendingIntentAction> actions;

    /**
     * 可见即可说事件
     */
    private List<IPendingIntentAction> seeSayActions;

    /**
     * 场景卡片
     */
    private List<IPendingIntentAction> smartCardActions;

    /**
     * 消息key
     */
    private String key;

    public ISceneCardInfo(int id, String pkgname, boolean beep, boolean tts, boolean seeSay, String title, String subtitle, String backgroud, String detailImg, String tag, long when, List<IPendingIntentAction> actions, List<IPendingIntentAction> seeSayActions, List<IPendingIntentAction> smartCardActions) {
        this.id = id;
        this.pkgname = pkgname;
        this.beep = beep;
        this.tts = tts;
        this.seeSay = seeSay;
        this.title = title;
        this.subtitle = subtitle;
        this.background = backgroud;
        this.detailImg = detailImg;
        this.tag = tag;
        this.when = when;
        this.actions = actions;
        this.seeSayActions = seeSayActions;
        this.smartCardActions = smartCardActions;
        this.key = key();
    }

    protected ISceneCardInfo(Parcel in) {
        id = in.readInt();
        pkgname = in.readString();
        beep = in.readByte() != 0;
        tts = in.readByte() != 0;
        seeSay = in.readByte() != 0;
        title = in.readString();
        subtitle = in.readString();
        background = in.readString();
        detailImg = in.readString();
        tag = in.readString();
        when = in.readLong();
        actions = in.createTypedArrayList(IPendingIntentAction.CREATOR);
        seeSayActions = in.createTypedArrayList(IPendingIntentAction.CREATOR);
        smartCardActions = in.createTypedArrayList(IPendingIntentAction.CREATOR);
        key = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(pkgname);
        dest.writeByte((byte) (beep ? 1 : 0));
        dest.writeByte((byte) (tts ? 1 : 0));
        dest.writeByte((byte) (seeSay ? 1 : 0));
        dest.writeString(title);
        dest.writeString(subtitle);
        dest.writeString(background);
        dest.writeString(detailImg);
        dest.writeString(tag);
        dest.writeLong(when);
        dest.writeTypedList(actions);
        dest.writeTypedList(seeSayActions);
        dest.writeTypedList(smartCardActions);
        dest.writeString(key);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<ecarx.xsf.notificationcenter.scenecard.ISceneCardInfo> CREATOR = new Creator<ecarx.xsf.notificationcenter.scenecard.ISceneCardInfo>() {
        @Override
        public ecarx.xsf.notificationcenter.scenecard.ISceneCardInfo createFromParcel(Parcel in) {
            return new ecarx.xsf.notificationcenter.scenecard.ISceneCardInfo(in);
        }

        @Override
        public ecarx.xsf.notificationcenter.scenecard.ISceneCardInfo[] newArray(int size) {
            return new ecarx.xsf.notificationcenter.scenecard.ISceneCardInfo[size];
        }
    };

    public String getSubtitle() {
        return subtitle;
    }

    public void setSubtitle(String subtitle) {
        this.subtitle = subtitle;
    }

    public List<IPendingIntentAction> getSmartCardActions() {
        return smartCardActions;
    }

    public void setSmartCardActions(List<IPendingIntentAction> smartCardActions) {
        this.smartCardActions = smartCardActions;
    }

    private String key() {
        return id + "|" + pkgname + "|" + tag;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getPkgname() {
        return pkgname;
    }

    public void setPkgname(String pkgname) {
        this.pkgname = pkgname;
    }

    public boolean isBeep() {
        return beep;
    }

    public void setBeep(boolean beep) {
        this.beep = beep;
    }

    public boolean isTts() {
        return tts;
    }

    public void setTts(boolean tts) {
        this.tts = tts;
    }


    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }


    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public long getWhen() {
        return when;
    }

    public void setWhen(long when) {
        this.when = when;
    }

    public List<IPendingIntentAction> getActions() {
        return actions;
    }

    public void setActions(List<IPendingIntentAction> actions) {
        this.actions = actions;
    }

    public List<IPendingIntentAction> getSeeSayActions() {
        return seeSayActions;
    }

    public String getKey() {
        return key;
    }

    public void setSeeSay(boolean seeSay) {
        this.seeSay = seeSay;
    }

    public boolean isSeeSay() {
        return seeSay;
    }

    public void setSeeSayActions(List<IPendingIntentAction> seeSayActions) {
        this.seeSayActions = seeSayActions;
    }

    public String getBackground() {
        return background;
    }

    public void setBackground(String background) {
        this.background = background;
    }

    public String getDetailImg() {
        return detailImg;
    }

    public void setDetailImg(String detailImg) {
        this.detailImg = detailImg;
    }

    @Override
    public int compareTo(@NonNull ecarx.xsf.notificationcenter.scenecard.ISceneCardInfo o) {
        if (when < o.when) {
            return 1;
        } else if (when > o.when) {
            return -1;
        }
        return 0;
    }

    @Override
    public String toString() {
        return "ISceneCardInfo{" +
                "id=" + id +
                ", pkgname='" + pkgname + '\'' +
                ", beep=" + beep +
                ", tts=" + tts +
                ", seeSay=" + seeSay +
                ", title='" + title + '\'' +
                ", subtitle='" + subtitle + '\'' +
                ", background='" + background + '\'' +
                ", detailImg='" + detailImg + '\'' +
                ", tag='" + tag + '\'' +
                ", when=" + when +
                ", actions=" + actions +
                ", seeSayActions=" + seeSayActions +
                ", smartCardActions=" + smartCardActions +
                ", key='" + key + '\'' +
                '}';
    }
}
